﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using WPFExcelReport.Helpers;
using System.Collections.Generic;
namespace WPFExcelReport
{
    /// <summary>
    /// 专用于布卷剪布
    /// </summary>
    public partial class UIWBDAT:ViewBase
    {
        
        public UIWBDAT()
        {

         }

        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);

        }
         
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwWB04 = dwMaster; 
           
            if (dwMaster == null)
            {
                KEY = "";
                WAART = "";
            }
            else
            {
                WAART = dwMaster["WBART"].ToString() + dwMaster["WBVAR"].ToString();
                KEY = dwMaster["WBRWKRS"].ToString() + dwMaster["WBRWLFD"].ToString();
                PARTIE = TMV.WBKDPART.PadRight(10) + TMV.WBLIEFDAT.ToString().PadRight(10) + TMV.WBART.PadRight(20) + TMV.WBFARBE.PadRight(10) + TMV.WBBESCHICH.PadRight(10);
            }
        }

        public override void ManageCommand(object sender, RoutedEventArgs e)
        {
            if (!IsManage) 
            {
                VICC_WFEVENTS.SVWF.WB02(RUNID);
            }
            base.ManageCommand(sender, e);
        }

        public void EKWB(object sender, RoutedEventArgs e)
        {
            VICC_WFEVENTS.SVWF.EKWB(RUNID, KEY, LO, LB, LP);
        }
        public override void OnSave()
        {
            if (!IsSaved)
                return;
            try
            {
                foreach (DataRow row in TBMain.Rows)
                {
                    if (row.RowState == DataRowState.Unchanged) continue;
                    TMV.UpdateWBDAT(row, app.company, 0);
                } 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            base.OnSave();
        }
        
        public virtual void OnRWAUFChg(string value)
        { 
        }
        public virtual void OnEKAUFChg(string value)
        {
        }
        public virtual void OnISWB03Chg(bool value)
        {
        }

        public void ResetSeq(object sender, RoutedEventArgs e)
        {
            if (!TMV.IsITX)
            {
                return;
            }
            VSDDAT.SD22.RESETSEQ("0022", KRS, "WBDAT", "1");
            VSDDAT.SD22.RESETSEQ("0022", "  ", "BEWEGUNG", "1");
            dwData = TBMain.NewRow();
            dwData["WBMANDANT"] = app.Mandant;
            dwData["WBRWKRS"] = "  ";
            TMV.DWBD00(dwData);
            dwData = TMV.WBB.TBMain.NewRow();
            dwData["WBBMANDANT"] = app.Mandant;
            dwData["WBBRWKRS"] = "  ";
            TMV.WBB.DWBB00(dwData);
            dwData = TMV.VWG.TBMain.NewRow();
            dwData["WGMANDANT"] = app.Mandant; 
            TMV.VWG.DWG00(dwData);
             
            dwData = TMV.WBW.TBMain.NewRow();
            dwData["WBEWMANDANT"] = app.Mandant;
            dwData["WBEWAUFTYP"] = " ";
            dwData["WBEWAUFKRS"] = "  ";
            TMV.WBWT.DeleteWBBEW(dwData, 0); 
        }
        
    }
    public partial class UIWBDAT : ViewBase
    {
        public VWBDAT TMV
        {
            get
            {
                return (VWBDAT)MV;
            }
        }
        #region ==dwWG===========
        public static readonly DependencyProperty dwWGProperty = DependencyProperty.Register("dwWG",
            typeof(DataRow), typeof(UIWBDAT),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwWGChanged));
        public DataRow dwWG
        {
            get
            {
                return (DataRow)GetValue(dwWGProperty);
            }
            set
            {
                SetValue(dwWGProperty, value);

            }
        }
        private static void OndwWGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWBDAT;
            if (src != null)
            {
                src.dwWG = (DataRow)e.NewValue;
                src.OnWGChg((DataRow)e.NewValue);

            }
        }
        public virtual void OnWGChg(DataRow _dwWG)
            {

        }
        #endregion
        #region ==ROLLS===========
        public static readonly DependencyProperty ROLLSProperty = DependencyProperty.Register("ROLLS",
            typeof(double), typeof(UIWBDAT),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnROLLSChanged));
        public double ROLLS
        {
            get
            {
                return (double)GetValue(ROLLSProperty);
            }
            set
            {
                SetValue(ROLLSProperty, value);
            }
        }
        private static void OnROLLSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWBDAT;
            if (src != null)
            {
                src.ROLLS = (double)e.NewValue;
            }
        }
        #endregion

        #region ==RLG===========
        public static readonly DependencyProperty RLGProperty = DependencyProperty.Register("RLG",
            typeof(double), typeof(UIWBDAT),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnRLGChanged));
        public double RLG
        {
            get
            {
                return (double)GetValue(RLGProperty);
            }
            set
            {
                SetValue(RLGProperty, value);
            }
        }
        private static void OnRLGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWBDAT;
            if (src != null)
            {
                src.RLG = (double)e.NewValue;
            }
        }
        #endregion

        #region ==EKAUF===========
        public static readonly DependencyProperty EKAUFProperty = DependencyProperty.Register("EKAUF",
            typeof(string), typeof(UIWBDAT),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnEKAUFChanged));
        public string EKAUF
        {
            get
            {
                return (string)GetValue(EKAUFProperty);
            }
            set
            {
                SetValue(EKAUFProperty, value);
                OnEKAUFChg(value);
            }
        }
        private static void OnEKAUFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWBDAT;
            if (src != null)
            {
                src.EKAUF = (string)e.NewValue;
            }
        }
        #endregion
        
        #region ==RWAUF===========
        public static readonly DependencyProperty RWAUFProperty = DependencyProperty.Register("RWAUF",
            typeof(string), typeof(UIWBDAT),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnRWAUFChanged));
        public string RWAUF
        {
            get
            {
                return (string)GetValue(RWAUFProperty);
            }
            set
            {
                SetValue(RWAUFProperty, value);
                OnRWAUFChg(value);
            }
        }
        private static void OnRWAUFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWBDAT;
            if (src != null)
            {
                src.RWAUF = (string)e.NewValue;
            }
        }
        #endregion

        #region ==WAKZ===========
        public static readonly DependencyProperty WAKZProperty = DependencyProperty.Register("WAKZ",
            typeof(string), typeof(UIWBDAT),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWAKZChanged));
        public string WAKZ
        {
            get
            {
                return (string)GetValue(WAKZProperty);
            }
            set
            {
                SetValue(WAKZProperty, value);
            }
        }
        private static void OnWAKZChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWBDAT;
            if (src != null)
            {
                src.WAKZ = (string)e.NewValue;
            }
        }
        #endregion

        #region ==CART===========
        public static readonly DependencyProperty CARTProperty = DependencyProperty.Register("CART",
            typeof(string), typeof(UIWBDAT),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCARTChanged));
        public string CART
        {
            get
            {
                return (string)GetValue(CARTProperty);
            }
            set
            {
                SetValue(CARTProperty, value);
            }
        }
        private static void OnCARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWBDAT;
            if (src != null)
            {
                src.CART = (string)e.NewValue;
            }
        }
        #endregion

        #region ==CFARBE===========
        public static readonly DependencyProperty CFARBEProperty = DependencyProperty.Register("CFARBE",
            typeof(string), typeof(UIWBDAT),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCFARBEChanged));
        public string CFARBE
        {
            get
            {
                return (string)GetValue(CFARBEProperty);
            }
            set
            {
                SetValue(CFARBEProperty, value);
            }
        }
        private static void OnCFARBEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWBDAT;
            if (src != null)
            {
                src.CFARBE = (string)e.NewValue;
            }
        }
        #endregion

        #region ==dwWB04===========
        public static readonly DependencyProperty dwWB04Property = DependencyProperty.Register("dwWB04",
            typeof(DataRow), typeof(UIWBDAT),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwWB04Changed));
        public DataRow dwWB04
        {
            get
            {
                return (DataRow)GetValue(dwWB04Property);
            }
            set
            {
                SetValue(dwWB04Property, value);
            }
        }
        private static void OndwWB04Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWBDAT;
            if (src != null)
            {
                src.dwWB04 = (DataRow)e.NewValue;
            }
        }
        #endregion

        #region ==dwWS===========
        public static readonly DependencyProperty dwWSProperty = DependencyProperty.Register("dwWS",
            typeof(DataRow), typeof(UIWBDAT),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwWSChanged));
        public DataRow dwWS
        {
            get
            {
                return (DataRow)GetValue(dwWSProperty);
            }
            set
            {
                SetValue(dwWSProperty, value);
                OnWSChg();
            }
        }
        private static void OndwWSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWBDAT;
            if (src != null)
            {
                src.dwWS = (DataRow)e.NewValue;
            }
        }
        public virtual void OnWSChg()
        { }
        #endregion

        #region ==dwWF===========
        public static readonly DependencyProperty dwWFProperty = DependencyProperty.Register("dwWF",
            typeof(DataRow), typeof(UIWBDAT),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwWFChanged));
        public DataRow dwWF
        {
            get
            {
                return (DataRow)GetValue(dwWFProperty);
            }
            set
            {
                SetValue(dwWFProperty, value);
                OnWFChg();
            }
        }
        private static void OndwWFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWBDAT;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwWF = (DataRow)e.NewValue;
               
            }
        }
        public virtual void OnWFChg()
        {
            if (dwWF != null)
            {
                CART = dwWF["WAFART"].ToString() + dwWF["WAFVAR"].ToString();
                CFARBE = dwWF["WAFZUSATZ"].ToString();
            }
            else
            {
                CART = "";
            }
        }
        #endregion

        #region ==dwEKP===========
        public static readonly DependencyProperty dwEKPProperty = DependencyProperty.Register("dwEKP",
            typeof(DataRow), typeof(UIWBDAT),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwEKPChanged));
        public DataRow dwEKP
        {
            get
            {
                return (DataRow)GetValue(dwEKPProperty);
            }
            set
            {
                SetValue(dwEKPProperty, value);
            }
        }
        private static void OndwEKPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWBDAT;
            if (src != null)
            {
                src.dwEKP = (DataRow)e.NewValue;
            }
        }
        #endregion

        #region ==WAART===========
        public static readonly DependencyProperty WAARTProperty = DependencyProperty.Register("WAART",
            typeof(string), typeof(UIWBDAT),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWAARTChanged));
        public string WAART
        {
            get
            {
                return (string)GetValue(WAARTProperty);
            }
            set
            {
                SetValue(WAARTProperty, value);
            }
        }
        private static void OnWAARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWBDAT;
            if (src != null)
            {
                src.WAART = (string)e.NewValue;
            }
        }
        #endregion

        #region ==IsWB03===========
        public static readonly DependencyProperty IsWB03Property = DependencyProperty.Register("IsWB03",
            typeof(bool), typeof(UIWBDAT),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsWB03Changed));
        public bool IsWB03
        {
            get
            {
                return (bool)GetValue(IsWB03Property);
            }
            set
            {
                SetValue(IsWB03Property, value);
                OnISWB03Chg(value);
            }
        }
        private static void OnIsWB03Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWBDAT;
            if (src != null)
            {
                src.IsWB03 = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==ACTRLFD===========
        public static readonly DependencyProperty ACTRLFDProperty = DependencyProperty.Register("ACTRLFD",
            typeof(double), typeof(UIWBDAT),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnACTRLFDChanged));
        public double ACTRLFD
        {
            get
            {
                return (double)GetValue(ACTRLFDProperty);
            }
            set
            {
                SetValue(ACTRLFDProperty, value);
                OnACTRLFDChg();
            }
        }
        private static void OnACTRLFDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWBDAT;
            if (src != null)
            {
                src.ACTRLFD = (double)e.NewValue;
            }
        }
        public virtual void OnACTRLFDChg()
        { }
        #endregion
        #region ==dwRule===========
        public static readonly DependencyProperty dwRuleProperty = DependencyProperty.Register("dwRule",
          typeof(DataRow), typeof(UIWBDAT),
          new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OdwRuleChanged));
        public DataRow dwRule
        {
            get
            {
                return (DataRow)GetValue(dwRuleProperty);

            }
            set
            {
                try
                {
                    SetValue(dwRuleProperty, value); 
                }
                catch (Exception ex)
                {
                    Tracer.Error(ex.StackTrace, ex);
                }
            }
        }
        private static void OdwRuleChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWBDAT;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwRule = row;
            }
        }
        #endregion 

        #region ==dwABP===========
        public static readonly DependencyProperty dwABPProperty = DependencyProperty.Register("dwABP",
            typeof(DataRow), typeof(UIWBDAT),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwABPChanged));
        public DataRow dwABP
        {
            get
            {
                return (DataRow)GetValue(dwABPProperty);
            }
            set
            {
                SetValue(dwABPProperty, value);
            }
        }
        private static void OndwABPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWBDAT;
            if (src != null)
            {
                src.dwABP = (DataRow)e.NewValue;
            }
        }
        #endregion

        #region ==IsAppend===========
        public static readonly DependencyProperty IsAppendProperty = DependencyProperty.Register("IsAppend",
            typeof(bool), typeof(UIWBDAT),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsAppendChanged));
        public bool IsAppend
        {
            get
            {
                return (bool)GetValue(IsAppendProperty);
            }
            set
            {
                SetValue(IsAppendProperty, value);
                OnIsAppendChg(value);
            }
        }
        private static void OnIsAppendChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWBDAT;
            if (src != null)
            {
                src.IsAppend = (bool)e.NewValue;
            }
        }
        public virtual void OnIsAppendChg(bool _IsAppend)
        {

        }
        #endregion

        #region ==STKNR===========
        public static readonly DependencyProperty STKNRProperty = DependencyProperty.Register("STKNR",
            typeof(string), typeof(UIWBDAT),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSTKNRChanged));
        public string STKNR
        {
            get
            {
                return (string)GetValue(STKNRProperty);
            }
            set
            {
                SetValue(STKNRProperty, value);
            }
        }
        private static void OnSTKNRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWBDAT;
            if (src != null)
            {
                src.STKNR = (string)e.NewValue;
            }
        }
        #endregion

        #region ==VKDELDATE===========
        public static readonly DependencyProperty VKDELDATEProperty = DependencyProperty.Register("VKDELDATE",
            typeof(string), typeof(UIWBDAT),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVKDELDATEChanged));
        public string VKDELDATE
        {
            get
            {
                return (string)GetValue(VKDELDATEProperty);
            }
            set
            {
                SetValue(VKDELDATEProperty, value);
            }
        }
        private static void OnVKDELDATEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWBDAT;
            if (src != null)
            {
                src.VKDELDATE = (string)e.NewValue;
            }
        }
        #endregion

        
    }
}
